import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/testApp',
    name: 'testApp',
    component: () => import('@/views/testApp')
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('@/views/Login/index.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/Home'),
    redirect: '/message',
    children: [
      { // 消息页
        path: '/message',
        name: 'message',
        component: () => import('@/pages/message')
      },
      { // 通讯录页
        path: '/addressList',
        redirect: '/addressList/myFriends',
        name: 'addressList',
        component: () => import('@/pages/addressList'),
        children: [
          {
            // 我的好友页
            path: '/addressList/myFriends',
            name: 'myFriends',
            component: () => import('@/pages/addressList/components/myfriends')
          },
          {
            // 群组
            path: '/addressList/group',
            name: 'group',
            component: () => import('@/pages/addressList/components/group')
          },
          {
            // 好友申请
            path: '/addressList/friendApply',
            name: 'friendApply',
            component: () => import('@/pages/addressList/components/friendApply')
          }
        ]
      },
      { // 会议处理页
        path: '/conference',
        redirect: '/conference/agendaCf',
        name: 'conference',
        component: () => import('@/pages/conference'),
        children: [
          {
            path: '/conference/agendaCf',
            redirect: '/conference/agendaCf/main',
            name: 'agendaCf',
            component: () => import('@/pages/conference/components/agendaCf'),
            children: [
              {
                path: '/conference/agendaCf/main',
                name: 'agendaCfMain',
                component: () => import('@/pages/conference/components/agendaCf/components/main')
              },
              {
                path: '/conference/agendaCf/edit',
                name: 'agendaCfEdit',
                component: () => import('@/pages/conference/components/reserveCf')
              }
            ]
          },
          {
            path: '/conference/joinCf',
            name: 'joinCf',
            component: () => import('@/pages/conference/components/joinCf')
          },
          {
            path: '/conference/quickCf',
            name: 'quickCf',
            component: () => import('@/pages/conference/components/quickCf')
          },
          {
            path: '/conference/reserveCf',
            name: 'reserveCf',
            component: () => import('@/pages/conference/components/reserveCf')
          },
          {
            path: '/conference/historyCf',
            name: 'historyCf',
            component: () => import('@/pages/conference/components/historyCf')
          }
        ]
      },
      { // 文档页
        path: '/file',
        name: 'file',
        component: () => import('@/pages/file')
      }]
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/pages/register'),
    children: [{
      path: '/signUp',
      name: 'signUp',
      component: () => import('@/pages/register/signUp')
    },
    {
      path: '/findPassword',
      name: 'findPassword',
      component: () => import('@/pages/register/findPassword')
    }]
  },
  {
    path: '/conferenceRoom',
    name: 'conferenceRoom',
    component: () => import('@/pages/conferenceRoom')
  },
  {
    path: '/resetPassword',
    name: 'resetPassword',
    component: () => import('@/pages/resetPassword')
  },
  {
    path: '/videoCall',
    name: 'videoCall',
    component: () => import('@/pages/videoCall')
  }
]

// 解决路由地址重复导致的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
